<?php
namespace app\admin\logic;

use app\common\model\UserModel;

class UserLogic extends UserModel
{
	
	public function getPage($where = [])
	{
		//排序
		$order = [
				'status' => 'DESC',
				$this->getPk() => 'DESC',
		];
		//查询数据
		$data = $this->where($where)->order($order)->paginate(10);

		//字段属性映射
		foreach ($data as $key => &$val)
		{
			$this->attributeMap($val);
		}
		
		return $data;
	}

	public function updateRecord($data = [])
	{
		//入库
		$data = $this->allowField(true)->save($data, [$this->getPk() => $data['id']]);
		
		if( $data === false )
		{
			return false;
		}
		
		return true;
	}
	
	public function destroyRecord($id = 0)
	{
	    $where = [$this->getPk() => $id];

		return $this->where($where)->delete();
	}

	public function getDetail($where = [])
	{
		//查询数据
		$data = $this->where($where)->find();

		//字段属性映射
		$data = $this->attributeMap($data);

		return $data;
	}

    /**
     * 获取user
     * @param $data
     * @return array|bool
     */
    public function getUser($data)
    {
        $where['password'] = $data['username'];

        $user = $this->where($where)->find();

        return $user;
	}
};